Repository navigation
fix(confidence): a probability too wide for a double is no number, not a crash - #1405
Conversation
…r, not as a crash jev_confidence caught TypeError and ValueError but not OverflowError, so a 400-digit integer probability from JSON escaped a function whose docstring promises no number rather than a made-up one.
24 PRs. Vietnamese kept off the English checkpoint (#1392), deciding-window attribution preserved through end hooks (#1369), RemoteRouter identifying itself with a configurable User-Agent (#1396), ten more inputs refused where they enter (#1372, #1394, #1397, #1398, #1400, #1401, #1402, #1403, #1404, #1405, #1406), per-language temperatures and per-call budgets in .NET and Rust (#1370, #1371), .NET calibration files (#1384), the Go router lifecycle, SHA-256 pins and routed inference (#1374, #1379, #1395), a C++ foundation (#1399, #1407), and parity-lane sharding that replaces the budget headroom added for 0.4.16 (#1373, #1375). Verified before tagging: all 92 suites pass, 640 tests, up from 612. ruff clean on both lists. laya-ts 1251 tests across 44 files, tsc --noEmit clean. Every generated-artifact gate clean on CPython 3.12 / unicodedata 15.0.0: Java 20 families match laya (9 unverified), UnicodeTables matches CPython 15.0.0, LanguageTables matches laya/lang.py, three Go tables_gen.go match, both laya-cpp .inc files match. Version agrees across pyproject.toml, laya.__version__ and nix/package.nix. README carries 0.4.17 only. Security audit of the merge diff, 362766 added lines over 480 files: zero obfuscation, zero secrets, zero boundary hits, zero binaries, no mode or symlink changes, 20 of 20 actions SHA-pinned including the new cpp.yml, npm install hooks unchanged, and no third-party host in any added line (example.com 90, github.com 2, download.pytorch.org 1, docs.rs 1). The 12 dynamic-exec hits are the C++ test harness invoking its own checker through sys.executable, the Go sample generator reading laya's own example by AST at development time, and one comment in rust.yml. Held: #1364 (unchanged, it moves a cross-port contract), #1381 (a #[doc(hidden)] but pub Rust hook that would ship as public API able to replace the forward pass), #1386 (route_batch switched from self.route to self._route, silently bypassing subclass overrides the docstring promises), and nine stacked port PRs that conflict with each other and need linearizing (#1377, #1378, #1380, #1382, #1383, #1385, #1387, #1388, #1389, #1390). Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
|
Merged. Treating The test cases are the strongest part. One small note, not a change request for this PR. The new comment cites Shipped in 0.4.17. |
…wError twin #1405's comment pointed at `calibrate.py:780`, which drifts the moment anything above it moves. The guard it means is the `version` field's `except (TypeError, ValueError, OverflowError)` inside `apply_calibration_payload`, so name that instead. Comment only, no behaviour change. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
What
jev_confidence's malformed-document arm catchesOverflowErroras well asTypeErrorandValueError. Three types in oneexcept, no new message, no behaviour change for any input that returns a number today.Why
laya/confidence.py:48-51states the contract: "a malformed document -- a probability that does not read as a number, a boolean, a non-finite or a negative value -- gives None rather than a guess, so a caller filtering on this number never filters on a made-up one." The coercion at:62-68only caught two of the three ways that conversion fails:JSON has no double limit. A model or a client that emits a 400-digit integer literal parses through
json.loadsinto a Pythonint, andfloat()on that raisesOverflowError, which walks straight out ofjev_confidence-- past theNonethe docstring promises and past the caller'sif jev_confidence(answer) < floorfilter. Both arms of thetryleak it:The third row is the same omission on the level keys rather than the values, which is why it is in the suite too. The module family already treats this exception as part of "not a number":
calibrate.py:780catches(TypeError, ValueError, OverflowError)with the comment "Overflow: JSON's 1e999 is inf",calibrate.py:80catches the same three, andhooks.py:275was fixed for exactly this pair of leaks.How it was verified
The three added rows are
("overflowing-integer-probability", ...),("json-integer-too-wide-for-a-double", ...)-- built withjson.loadsso the case is the real remote-body route, not a hand-written Python literal -- and("overflowing-score-level", ...)in the existingjev_confidence/none-for-%stable.Mutation arm, the
excepttuple reverted to two types with the tests kept: the suite stops on the leak it exists to catch, naming it:For the ports:
laya-rust/tools/confidence_cases.py::_jev_corpusis the pinned jev surface (copied to .NET), so I ran every one of its cases throughjev_confidencein this branch and in a pristineb9fe351worktree and compared the results as one blob -- 96 cases, digest7c10e13b0f4a69c7b008on both, so no corpus output moves: this only turns a crash into theNonethe corpus already records for the neighbouring shapes.laya-java/scripts/gen_fixtures.py --checkreports the same two families as a base worktree (lang_detect.json,python_json.json-- the Linux/macOS regeneration noted atgen_fixtures.py:1922), and neither family callsjev_confidence.Checklist
main